from datetime import datetime
from typing import Optional

from sqlmodel import SQLModel, Field

from app.models.base import TimestampMixin


class Article(TimestampMixin, table=True):
    __tablename__ = "article"

    id: int = Field(default=None, primary_key=True)
    cid: int = Field(gt=0)  # 分类ID，必须大于0
    title: str = Field(max_length=200, default="")
    intro: str = Field(max_length=200, default="")
    summary: Optional[str] = Field(max_length=200, default=None)
    image: str = Field(max_length=200, default="")
    content: Optional[str] = None  # 内容字段可以为空
    author: str = Field(max_length=32, default="")
    visit: int = Field(ge=0, default=0)  # 浏览数 >= 0
    sort: int = Field(ge=0, default=50)  # 排序 >= 0，默认50
    is_show: int = Field(default=0, ge=0, le=1)  # 是否显示: 0=否, 1=是
    is_delete: int = Field(default=0, ge=0, le=1)  # 是否删除: 0=否, 1=是


class ArticleCategory(TimestampMixin, table=True):
    __tablename__ = "article_category"

    id: int = Field(default=None, primary_key=True)  # 主键
    name: str = Field(max_length=60, min_length=1)  # 分类名称，长度限制为60字符
    sort: int = Field(ge=0, default=50)  # 排序字段，>=0，默认50
    is_show: int = Field(default=1, ge=0, le=1)  # 是否显示: [0=否, 1=是]
    is_delete: int = Field(default=0, ge=0, le=1)  # 是否删除: [0=否, 1=是]


class ArticleCollect(TimestampMixin, table=True):
    __tablename__ = "article_collect"

    id: int = Field(default=None, primary_key=True)  # 主键
    user_id: int = Field(gt=0)  # 用户ID，必须大于0
    article_id: int = Field(gt=0)  # 文章ID，必须大于0
    is_delete: int = Field(default=0, ge=0, le=1)  # 是否删除: [0=否, 1=是]
